<template>
  <el-dialog :title="info.title" :visible.sync="visible" center width="460px" :before-close="handleCancel">
    <el-form ref="formDate" label-suffix=":" label-width="100px" :rules="rules" :model="form">
      <el-row>
        <el-col :span="24">
          <el-form-item label="保单号" prop="num">
            <el-input v-model="form.num" size="small" clearable />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="险种" prop="type">
            <el-select
              v-model="form.type"
              size="small"
              remote
              filterable
              style="width: 100%"
              placeholder="请选择"
              clearable
            >
              <el-option
                v-for="item in types"
                :key="item.key"
                :label="item.value"
                :value="item.key"
              />
            </el-select>
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="生效时间" prop="begin_time">
            <el-date-picker
              v-model="form.begin_time"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              size="small"
              clearable
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="截止时间" prop="end_time">
            <el-date-picker
              v-model="form.end_time"
              type="date"
              format="yyyy-MM-dd"
              value-format="yyyy-MM-dd"
              size="small"
              clearable
              style="width: 100%"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注" prop="remark">
            <el-input type="textarea" :rows="4" v-model="form.remark" size="small" clearable />
          </el-form-item>
        </el-col>
      </el-row>
      <el-row>
        <el-col :span="24">
          <div class="fr mt10">
            <el-button size="small" @click="handleCancel()">取 消</el-button>
            <el-button type="primary" size="small" @click="handleEdit()">保 存</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
  </el-dialog>
</template>

<script>
import { addInsure, updInsure, insureTypes } from '@/api/personnel/insure'
import form from '@/utils/form'

export default {
  extends: form,
  props: {
    reqAdd: {
      default: addInsure,
      type: Function
    },
    reqUpd: {
      default: updInsure,
      type: Function
    }
  },
  data() {
    return {
      types: [],
      rules: {
        num: [{ required: true, trigger: 'blur', message: '保单号不可为空' }],
        type: [{ required: true, trigger: 'blur', message: '险种不可为空' }],
        begin_time: [{ required: true, trigger: 'blur', message: '生效时间不可为空' }],
        end_time: [{ required: true, trigger: 'blur', message: '截止时间不可为空' }]
      }
    }
  },
  watch: {
    visible(val) {
      if (val) {
        this.form = this.info.edit
        this.insureTypes()
      }
    },
    getData: {
      type: Function,
      default: function() {}
    }
  },
  mounted() {
  },
  methods: {
    insureTypes() {
      insureTypes({}).then(response => {
        this.types = response.list
      }).catch(err => {
        this.$message.error(err.msg)
      })
    }
  }
}
</script>

<style>

</style>
